package nl.hva.three2learn.util;

import java.util.Random;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Password {
	public static String generateString(String characters, int passLength)
	{
		Random rng = new Random();
		char[] text = new char[passLength];
		
		int length = characters.length();
		for (int i = 0; i < passLength; i++)
	    {
	        text[i] = characters.charAt(rng.nextInt(length));
	    }
	    return new String(text);
	}
	
	public static String genHash(String password, String salt){
		//Todo: Actually create hash
		byte[] sum = null;
		try {
			MessageDigest mesDigest = MessageDigest.getInstance("MD5");
			sum = mesDigest.digest((password + salt).getBytes());
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return new String(sum);
	}
}
